package com.cmii.sjw.department.control.jsc.controller;

import cn.hutool.core.util.ObjectUtil;
import com.cmii.sjw.department.control.jsc.model.User;
import com.cmii.sjw.department.control.jsc.model.dto.UserQueryDTO;
import com.cmii.sjw.department.control.jsc.service.IUserService;
import com.cmii.sjw.department.control.jsc.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息
 * @Author jfh
 * @Date 2024-11-12 周二 15:05
 * @Version 1.0
 */
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     * 根据条件分页查询用户列表
     * @author jfh
     * @Date 2025/5/27 14:19
     * @param param 用户信息
     * @return com.cmii.sjw.department.control.jsc.util.Result
     */
    @PostMapping("/list")
    public Result list(@RequestBody UserQueryDTO param) {
        log.info("查询用户列表:{}", param);
        return Result.success(userService.selectUserList(param));
    }

    /**
     * 修改用户信息
     * @author jfh
     * @Date 2025/5/27 11:46
     * @param param 用户信息
     * @return com.cmii.sjw.department.control.jsc.util.Result
     */
    @PostMapping("/update")
    public Result<String> update(@RequestBody UserQueryDTO param) {
        log.info("修改用户信息:{}", param);

        if (ObjectUtil.isEmpty(param)){
            return Result.error("参数不能为空");
        }
        if (param.getUserId() == null) {
            return Result.error("用户ID不能为空");
        }
        User user = new User();
        BeanUtils.copyProperties(param,user);
        return Result.success(userService.updateById(user));
    }
}
